open GMain
open Graphics

let main (str) =
  let window = GWindow.window ~title: "ML Gears" () in
  window#connect#destroy ~callback:Main.quit;
  window#set_resize_mode `IMMEDIATE;

  let table = GPack.table ~rows: 2 ~columns: 3 ~packing: window#add () in

  let area = Graphics.getGlArea (table#attach ~left: 1 ~top: 0 ~expand: `BOTH)
  600 400 in

  let view = new view area in
  let obj = new ObjFile.obj_file in
  obj#load_from(str);
  view#add(obj :> render);
  obj#save_to "fail";
  let scale ~orientation ~callback ~value ?packing () =
    let adjustment = GData.adjustment ~lower: 0.0 ~upper: 360.0 () in
    adjustment#connect#value_changed
      ~callback: (fun () -> callback adjustment#value);
    adjustment#set_value value;
    GRange.scale orientation ~adjustment ~draw_value: false ?packing ()
  in
  let sx = scale ~orientation: `VERTICAL ~callback: view#rotx  ~value: 40.0
      ~packing: (table#attach ~left: 2 ~top: 0 ~expand: `Y) () in
  let sy = scale ~orientation: `HORIZONTAL ~callback: view#roty ~value: 20.0
      ~packing: (table#attach ~left: 1 ~top: 1 ~expand: `X) () in
  let sz = scale ~orientation: `VERTICAL ~callback: view#rotz ~value: 10.0
      ~packing: (table#attach ~left: 0 ~top: 0 ~expand: `Y) () in

  Timeout.add ~ms: 20 ~callback: view#idle;
  window#show ();
  Main.main ()
